package de.drkarl.verhalten;

import java.util.LinkedList;



import de.drkarl.charakters.Animal;
import de.drkarl.charakters.Beute;

public abstract class Angriffsverhalten {

	Animal animal;

	public Angriffsverhalten(Animal animal) {
		super();
		this.animal = animal;
	}
	
	public LinkedList<Position> filedsToGo(int speed){
		LinkedList<Position> positionen = new LinkedList<Position>();
		int xField = animal.getSpielfeld().xSize;
		int yField = animal.getSpielfeld().ySize;
		int xCurrentAnimal = animal.getxPosition();
		int yCurrentAnimal = animal.getyPosition();
		
		for (int i = 0; i < yField; i++) {
			for (int j = 0; j < xField; j++) {
				if(i>=(yCurrentAnimal-speed)&&i<=yCurrentAnimal+speed){
					if(j>=(xCurrentAnimal-speed)&&j<=(xCurrentAnimal+speed)){
						
						Position b = new Position(j, i);
						
						positionen.addLast(b);
					}
				}
			}
		}
		return positionen;
	}
	
	public LinkedList<Position> scan(int reichweite){
		LinkedList<Position> positionen = new LinkedList<Position>();
		int xCurrentAnimal = animal.getxPosition();
		int yCurrentAnimal = animal.getyPosition();
				for (Animal animalInList : animal.getSpielfeld().getAnimals()) {
					if(animalInList.yPosition>=(yCurrentAnimal-reichweite)&&animalInList.yPosition<=yCurrentAnimal+reichweite){
						if(animalInList.xPosition>=(xCurrentAnimal-reichweite)&&animalInList.xPosition<=(xCurrentAnimal+reichweite)){
							
							Position b = new Position(animalInList.xPosition, animalInList.yPosition);
							if(animalInList instanceof Beute){
								b.setType(0);
							}else{
								b.setType(1);
							}
							positionen.addLast(b);
						}
					}
				}

		return positionen;
	}
	
	public void DoAngriff(){
		angriff();
	}
	public abstract void angriff();
	
}
